/*
 * Copyright 2010 Katsunori Koyanagi
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package sweezy.anim.core
{
	import sweezy.anim.impl.AnimationManager;

	use namespace anim_internal;

	public class Animator
	{

		private static var _manager:IAnimationManager = new AnimationManager();

		private static var _managerClass:Class = AnimationManager;

		public static function action(animation:IAnimation, action:IAction, quePosition:uint):IAnimationDecorator
		{
			return _manager.createActionAnimation(animation, action, quePosition);
		}

		public static function animate(element:Object, duration:uint = 0, easing:IEasing = null, delay:uint = 0):IPropertyAnimation
		{
			return _manager.createPropertyAnimation(element, duration, easing, delay);
		}

		public static function animate2(element:Object, properties:Object = null):IPropertyAnimation
		{
			return _manager.createPropertyAnimationByProperties(element, properties);
		}

		public static function get defaultDuration():uint
		{
			return _manager.defaultDuration;
		}

		public static function set defaultDuration(value:uint):void
		{
			_manager.defaultDuration = value;
		}

		public static function get defaultEasing():IEasing
		{
			return _manager.defaultEasing;
		}

		public static function set defaultEasing(value:IEasing):void
		{
			_manager.defaultEasing = value;
		}

		public static function deregisterUpdaterByElementType(elementType:Class):void
		{
			_manager.deregisterUpdaterByElementType(elementType);
		}

		public static function deregisterUpdaterByPrefix(prefix:String):void
		{
			_manager.deregisterUpdaterByPrefix(prefix);
		}

		public static function easing(animation:IAnimation, easing:IEasing):IAnimationDecorator
		{
			return _manager.createEasingAnimation(animation, easing);
		}

		public static function empty(duration:uint = 0):IAnimation
		{
			return _manager.createEmptyAnimation(duration);
		}

		public static function getRelatedAnimations(element:Object):Array
		{
			return _manager.getRelatedAnimations(element);
		}

		public static function get manager():IAnimationManager
		{
			return _manager;
		}

		public static function padding(animation:IAnimation, before:uint, after:uint = 0):IAnimationDecorator
		{
			return _manager.createPaddingAnimation(animation, before, after);
		}

		public static function parallel(animation:IAnimation, ... animations):IAnimationGroup
		{
			animations.unshift(animation);
			return _manager.createParallelAnimation(animations);
		}

		public static function pauseRelatedAnimations(element:Object):void
		{
			_manager.pauseRelatedAnimations(element);
		}

		public static function phisycal(element:Object, easing:IPhisycalEasing = null, delay:uint = 0):IPropertyAnimation
		{
			return _manager.createPhisycalEasingAnimation(element, easing, delay);
		}

		public static function registerUpdaterByElementType(elementType:Class, updater:IUpdater):void
		{
			_manager.registerUpdaterByElementType(elementType, updater);
		}

		public static function registerUpdaterByPrefix(prefix:String, updater:IUpdater):void
		{
			_manager.registerUpdaterByPrefix(prefix, updater);
		}

		public static function repeat(animation:IAnimation, numRepeat:uint = 0):IAnimationDecorator
		{
			return _manager.createRepeatAnimation(animation, numRepeat);
		}

		public static function reverse(animation:IAnimation):IAnimationDecorator
		{
			return _manager.createReverseAnimation(animation);
		}

		public static function roundTrip(animation:IAnimation):IAnimationDecorator
		{
			return _manager.createRoundTripAnimation(animation);
		}

		public static function scale(animation:IAnimation, scale:Number):IAnimationDecorator
		{
			return _manager.createScaledAnimation(animation, scale);
		}

		public static function serial(animation:IAnimation, ... animations):IAnimationGroup
		{
			animations.unshift(animation);
			return _manager.createSerialAnimation(animations);
		}

		public static function slice(animation:IAnimation, startPosition:uint, sliceDuration:uint = 0):IAnimationDecorator
		{
			return _manager.createSlicedAnimation(animation, startPosition, sliceDuration);
		}

		public static function updateNow():void
		{
			_manager.updateNow();
		}

		anim_internal static function get managerClass():Class
		{
			return _managerClass;
		}

		anim_internal static function set managerClass(value:Class):void
		{
			_managerClass = value;
			if (value !== null)
			{
				_manager = new value();
			}
			else
			{
				_manager = new AnimationManager();
				_managerClass = AnimationManager;
			}
		}
	}
}
